import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.reflect.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;

/**
 * Server for keynote related things.
 */
class KeynoteServer extends LocalServer {

  private final Robot robot;
  { 
    Robot tmpRobot = null;
    try {
      tmpRobot = new Robot();
    } catch (Exception e) {handle(e);}
    robot = tmpRobot;
  }
  protected boolean showIP() {return true;}

  /** Tell keynote 'Back' */
  private class BackHandler extends AbstractHandler {
    public String handle(Map<String,String> args) {
      press(KeyEvent.VK_KP_LEFT);
      return "ok";
    }
    BackHandler() {
      super("Back");
    }
  }

  /** Tell keynote 'Next' */
  private class NextHandler extends AbstractHandler {
    public String handle(Map<String,String> args) {
      press(KeyEvent.VK_KP_RIGHT);
      return "ok";
    }
    NextHandler() {
      super("Next");
    }
  }

  /** Tell keynote 'Space' */
  private class SpaceHandler extends AbstractHandler {
    public String handle(Map<String,String> args) {
      press(KeyEvent.VK_SPACE);
      return "ok";
    }
    SpaceHandler() {
      super("Space");
    }
  }

  /** Tell keynote 'Space' */
  private class PressHandler extends AbstractHandler {
    public String handle(Map<String,String> args) {
      press(KeyEvent.VK_KP_LEFT);
      return "ok";
    }
    PressHandler() {
      super("Press");
    }
  }

  // -------------------- Private --------------------

  private void press(int keycode) {
    robot.keyPress(keycode);
  }


  Handler[] getHandlers() {
    return new Handler[] {
      new BackHandler(),
      new NextHandler(),
      new SpaceHandler(),
    };
  }

  public static void main(String args[]) {
    new KeynoteServer().realMain(args);
  }
  
}
